import javax.print.attribute.standard.MediaSizeName;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[] args) {
        int n = scanner.nextInt();
        int[][] queries = new int[n][2];
        for (int i = 0; i < n; i++) {
            queries[i][0] = scanner.nextInt();
            queries[i][1] = scanner.nextInt();
        }

        Solution solution = new Solution();
        System.out.println(solution.minOperations(queries));

    }

    public static void main3(String[] args) {
        int n = scanner.nextInt();
        Solution3 solution = new Solution3();

        int[] res = solution.sumZero(n);
        System.out.println(Arrays.toString(res));
    }

    public static void main2(String[] args) {
        int n = scanner.nextInt();
        Solution2 solution = new Solution2();

        int[] res = solution.getNoZeroIntegers(n);
        for (int x : res){
            System.out.println(x);
        }
    }

    public static void main1(String[] args) {

        Solution1 solution = new Solution1();

        String s = scanner.nextLine();

        System.out.println(solution.sortVowels(s));
    }
}

//class Solution {
//    public long minOperations(int[][] queries) {
//        int n = queries.length;
//        long res = 0;
//        for (int i = 0; i < n; i++) {
//            int sum = 0;
//            for (int j = queries[i][0]; j <= queries[i][1]; j++) {
//                int k = j;
//                while(k != 0){
//                    k /= 4;
//                    sum++;
//                }
//            }
//            if(sum%2 == 0){
//                 res = sum/2;
//            }else{
//                 res = sum/2 + 1;
//            }
//        }
//        return res;
//    }
//}

class Solution {
    public long minOperations(int[][] queries) {
        int n = queries.length;
        long res = 0;
        for (int i = 0; i < n; i++) {
            int sum = 0;
            for (int j = 0 ; j <= 20 ; j++) {
                int a = (int)Math.pow(4,j);
                if( a > queries[i][0] && a < queries[i][1]){
                    sum += (a-queries[i][0]) * j;
                } else if (a >= queries[i][1]) {
                    
                }
            }
            if(sum%2 == 0){
                res = sum/2;
            }else{
                res = sum/2 + 1;
            }
        }
        return res;
    }
}

class Solution3 {
    public int[] sumZero(int n) {
        int[] res = new int[n];
        if(n%2 == 0){
            for (int i = 0; i < n / 2; i++) {
                res[i] = i + 1;
                res[n - i - 1] = -(i + 1);
            }
        } else {
            for (int i = 0; i < n / 2; i++) {
                res[i] = i + 1;
                res[n - i - 1] = -(i + 1);
            }
            res[n / 2] = 0;
        }
        return res;
    }
}

class Solution2 {
    public int[] getNoZeroIntegers(int n) {
        int[] res = new int[2];

        for (int i = 1; i < n; i++) {
            boolean flag = true;
            int m = n - i;
            while(m !=0){
                int l = m % 10;
                if(l == 0){
                    flag = false;
                    break;
                }
                m/=10;
            }
            int j = i;
            while(j !=0){
                int l = j % 10;
                if(l == 0){
                    flag = false;
                    break;
                }
                j/=10;
            }
            if(flag){
                res[0] = i;
                res[1] = n - i;
                return res;
            }
        }
        return res;
    }
}

class Solution1 {
    public String sortVowels(String s) {
        StringBuffer t = new StringBuffer();
        String res = "";
        String c = "aeiouAEIOU";
        for (int i = 0; i < s.length(); i++) {
            char a = s.charAt(i);
            if(c.indexOf(a) != -1){
                t.append(a);
            }
        }
        char[] S = t.toString().toCharArray();
        Arrays.sort(S);

        int j = 0;
        for (int i = 0; i < s.length(); i++) {
            char a = s.charAt(i);
            if(c.indexOf(a) != -1){
                res += S[j++];
                continue;
            }
            res += a;
        }

        return res;
    }
}

